import { createApp } from 'vue'
import App from './App.vue'
import './style.css'

import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import router from './router'
import { createPinia } from 'pinia'
import { useUserStore } from '@/stores/user.js'

import { buildHeaderSign, getBaseURL } from '@/utils/headerSign'
import {
  buildUrl,
  getDate,
  getDate2,
  getDatetime,
  hideIdCardNumber,
  hidePhoneNumber,
  mergeArraysBykey,
  parseJsonObject,
  sortJsonObject,
} from '@/utils/common'
import { decryptAES, encryptAES } from '@/utils/secret'

const app = createApp(App)
const pinia = createPinia()

app.use(ElementPlus, { locale: zhCn }).use(router).use(pinia)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 初始化认证状态
const authStore = useUserStore() // 必须在 app.use(pinia) 之后
authStore.initUserData()

// 在这里添加全局属性或方法
app.config.globalProperties.$buildHeaderSign = buildHeaderSign
app.config.globalProperties.$getBaseURL = getBaseURL

app.config.globalProperties.$hidePhoneNumber = hidePhoneNumber
app.config.globalProperties.$hideIdCardNumber = hideIdCardNumber
app.config.globalProperties.$buildUrl = buildUrl
app.config.globalProperties.$getDatetime = getDatetime
app.config.globalProperties.$getDate = getDate
app.config.globalProperties.$getDate2 = getDate2
app.config.globalProperties.$parseJsonObject = parseJsonObject
app.config.globalProperties.$sortJsonObject = sortJsonObject
app.config.globalProperties.$mergeArraysBykey = mergeArraysBykey
app.config.globalProperties.$encryptAES = encryptAES
app.config.globalProperties.$decryptAES = decryptAES

app.mount('#app')
